home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Python 1.3.3 / Python 133 SRC / Mac / Modules / dlg / dlgscan.py < prev    next >
Text File  |  1996-04-12  |  2KB  |  84 lines

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2.  
  3. import addpack
  4. addpack.addpack(':Tools:bgen:bgen')
  5.  
  6. from scantools import Scanner
  7. from bgenlocations import TOOLBOXDIR
  8.  
  9. LONG = "Dialogs"
  10. SHORT = "dlg"
  11. OBJECT = "DialogPtr"
  12.  
  13. def main():
  14.     input = LONG + ".h"
  15.     output = SHORT + "gen.py"
  16.     defsoutput = TOOLBOXDIR + LONG + ".py"
  17.     scanner = MyScanner(input, output, defsoutput)
  18.     scanner.scan()
  19.     scanner.close()
  20.     print "=== Done scanning and generating, now importing the generated code... ==="
  21.     exec "import " + SHORT + "support"
  22.     print "=== Done.  It's up to you to compile it now! ==="
  23.  
  24. class MyScanner(Scanner):
  25.  
  26.     def destination(self, type, name, arglist):
  27.         classname = "Function"
  28.         listname = "functions"
  29.         if arglist:
  30.             t, n, m = arglist[0]
  31.             if t in ("DialogPtr", "DialogRef") and m == "InMode":
  32.                 classname = "Method"
  33.                 listname = "methods"
  34.         return classname, listname
  35.  
  36.     def makeblacklistnames(self):
  37.         return [
  38.             'InitDialogs',
  39.             'ErrorSound',
  40.             # Dialogs are disposed when the object is deleted
  41.             'CloseDialog',
  42.             'DisposDialog',
  43.             'DisposeDialog',
  44.             'UpdtDialog',
  45.             'CouldAlert',
  46.             'FreeAlert',
  47.             'CouldDialog',
  48.             'FreeDialog',
  49.             'GetStdFilterProc',
  50.             ]
  51.  
  52.     def makeblacklisttypes(self):
  53.         return [
  54.             ]
  55.  
  56.     def makerepairinstructions(self):
  57.         return [
  58.             ([("Str255", "*", "InMode")],
  59.              [("*", "*", "OutMode")]),
  60.             
  61.             ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
  62.              [("InBuffer", "*", "*")]),
  63.             
  64.             ([("void", "*", "OutMode"), ("long", "*", "InMode"),
  65.                                         ("long", "*", "OutMode")],
  66.              [("VarVarOutBuffer", "*", "InOutMode")]),
  67.              
  68.             # GetDialogItem return handle is optional
  69.             ([("Handle", "item", "OutMode")],
  70.              [("OptHandle", "item", "OutMode")]),
  71.             
  72.             # NewDialog ETC.
  73.             ([("void", "*", "OutMode")],
  74.              [("NullStorage", "*", "InMode")]),
  75.             
  76.             ([("DialogPtr", "*", "OutMode")],
  77.              [("ExistingDialogPtr", "*", "*")]),
  78.             ([("DialogRef", "*", "OutMode")],
  79.              [("ExistingDialogPtr", "*", "*")]),
  80.             ]
  81.  
  82. if __name__ == "__main__":
  83.     main()
  84.